package com.erhuogo.action;

import org.apache.struts2.ServletActionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.erhuogo.bean.GridPageBean;
import com.erhuogo.bean.Response;
import com.erhuogo.entity.Message;
import com.erhuogo.entity.Report;
import com.erhuogo.enumerate.Result;
import com.erhuogo.service.ReportService;
import com.opensymphony.xwork2.ActionSupport;

/**
 * 举报Action
 * @author aibinxiao
 * @date 2016年10月26日 上午11:34:46
 */
public class ReportAction extends ActionSupport {
	private static final long serialVersionUID = -7342158120556174513L;
	private static Logger logger = LoggerFactory.getLogger(ReportAction.class);
	
	// 模型驱动使用的对象
	private Report report;
	
	public Report getReport() {
		return report;
	}

	public void setReport(Report report) {
		this.report = report;
	}

	// 注入ReportService
	private ReportService reportService;

	public ReportService getReportService() {
		return reportService;
	}

	public void setReportService(ReportService reportService) {
		this.reportService = reportService;
	}
	
	// 返回页面数据
	private Response response = new Response();

	public Response getResponse() {
		return response;
	}

	public void setResponse(Response response) {
		this.response = response;
	}
	
	/**
	 * 1.分页条件查询留言信息
	 * @return
	 */
	public String listPage(){
		String page = ServletActionContext.getRequest().getParameter("page");
		String rows = ServletActionContext.getRequest().getParameter("rows");
		String id = ServletActionContext.getRequest().getParameter("id");
		String commodityId = ServletActionContext.getRequest().getParameter("commodityId");
		String acountId = ServletActionContext.getRequest().getParameter("acountId");
		String type = ServletActionContext.getRequest().getParameter("type");
		String handleStatus = ServletActionContext.getRequest().getParameter("handleStatus");
		String startDate = ServletActionContext.getRequest().getParameter("startDate");
		String endDate = ServletActionContext.getRequest().getParameter("endDate");
		GridPageBean<Report> listPage = reportService.findByPage(page, rows, id, commodityId, acountId ,type, handleStatus, startDate, endDate);
		if(listPage!=null && listPage.getRecords()>0){
			response.setResult(Result.SUCCESS.toString());
			response.setMessage("查询成功");
		}else{
			response.setResult(Result.FAILED.toString());
			response.setMessage("查询失败");
		}
		response.setData(listPage);
		return "listPageSUCCESS";
	}
	
	/**
	 * 2.根据id更新处理状态
	 * @return
	 */
	public String updateStatusById(){
		String id = ServletActionContext.getRequest().getParameter("id");
		String status = ServletActionContext.getRequest().getParameter("status");
		try {
			reportService.updateStatus(id,status);
			response.setResult(Result.SUCCESS.toString());
			response.setMessage("操作成功");
		} catch (Exception e) {
			response.setResult(Result.FAILED.toString());
			response.setMessage("操作失败");
			e.printStackTrace();
			logger.info(e.getMessage());
		}
		return "updateStatusSUCCESS";
	}
	
}
